package com.cino.basic.base.controller;


import com.cino.basic.base.dto.PhoneCodeDto;
import com.cino.basic.base.exception.BusinessException;
import com.cino.basic.base.service.VerifyCodeService;
import com.cino.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private VerifyCodeService verifyCodeService;

    @GetMapping("/image/{key}")
    public AjaxResult uploadFile(@PathVariable("key")String key ) {
        try {
          String base64Str=  verifyCodeService.getbase64Str(key);
            AjaxResult result = new AjaxResult();
            result.setObj(base64Str);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"网络异常，请稍后再试");
        }
    }

    @PostMapping("/mobile")
    public AjaxResult getPhoneCode(@RequestBody PhoneCodeDto dto){
        try {
            verifyCodeService.getPhoneCode(dto);
            AjaxResult result = new AjaxResult();
            return result;
        } catch (BusinessException e) {
            return  new AjaxResult(false, e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"系统繁忙，请稍后重试!!!");
        }
    }

    @PostMapping("/binderSmsCode")
    public AjaxResult getbinderSmsCode(@RequestBody PhoneCodeDto dto){
        try {
            verifyCodeService.getbinderSmsCode(dto);
            AjaxResult result = new AjaxResult();
            return result;
        } catch (BusinessException e) {
            return  new AjaxResult(false, e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"系统繁忙，请稍后重试!!!");
        }
    }

}
